using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TriggerEffectBuffer : MonoBehaviour
{
	[HideInInspector]
	public int viewID;

	[HideInInspector]
	public PunTeams.Team team;

	[HideInInspector]
	public bool isMine;

	public WeaponEffectSettings effectSettings;

	public float timeTick;

	public bool isAOEScene;

	private BoxCollider objCollider;

	private List<Mortal> damaged = new List<Mortal>();

	private void Start()
	{
		objCollider = GetComponent<BoxCollider>();
		objCollider.enabled = false;
		StartCoroutine(Work());
	}

	private IEnumerator Work()
	{
		while (true)
		{
			if (settings.offlineMode || isAOEScene)
			{
				objCollider.enabled = true;
			}
			else
			{
				objCollider.enabled = isMine;
			}
			damaged.Clear();
			yield return null;
			objCollider.enabled = false;
			yield return new WaitForSeconds(timeTick);
		}
	}

	public void OnTriggerEnter(Collider other)
	{
		Mortal componentInParent = other.gameObject.GetComponentInParent<Mortal>();
		if (!(componentInParent != null) || damaged.Contains(componentInParent))
		{
			return;
		}
		if (TDMController.isTeamGameType)
		{
			if (componentInParent is EntityBehavior)
			{
				EntityBehavior entityBehavior = componentInParent as EntityBehavior;
				PlayerBehavior playerBehavior = entityBehavior.getMainHuman() as PlayerBehavior;
				PlayerBehavior playerBehavior2 = GameController.instance.FindPlayer(entityBehavior.photonView.ownerId);
				if ((entityBehavior.getMainHuman() != null && playerBehavior != null && playerBehavior.localTeam == team && !entityBehavior.isMine) || (entityBehavior.privateCar && playerBehavior2 != null && playerBehavior2.localTeam == team))
				{
					return;
				}
			}
			else if (componentInParent is PlayerBehavior)
			{
				PlayerBehavior playerBehavior3 = componentInParent as PlayerBehavior;
				if (playerBehavior3.localTeam == team && !isMine)
				{
					return;
				}
			}
		}
		if (isAOEScene)
		{
			componentInParent.AddWeaponEffect((int)effectSettings.effectType, (int)effectSettings.damageType, effectSettings.effectDuration, effectSettings.effectPower, -9999);
		}
		else
		{
			componentInParent.AddWeaponEffect((int)effectSettings.effectType, (int)effectSettings.damageType, effectSettings.effectDuration, effectSettings.effectPower, GameController.instance.playerScript.viewId);
		}
		damaged.Add(componentInParent);
	}
}
